<?php

namespace app\api\controller\ykjp\product;

use app\common\controller\Backend;
use app\common\model\Category as CategoryModel;
use app\common\controller\Api;
use fast\Tree;


/**
 * 单位接口
 */
class Type extends Api
{

    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = '*';
   

    public function getType()
    {
        $this->model = new \app\admin\model\ykjp\product\Type;
        $row = $this->model->where('deletetime',null)->select();
        $categorydata= array();
        foreach ($row as $k => $v) {
            $categorydata[$k] = $v;
            $categorydata[$k]['image'] = $this->request->scheme() . "://".$_SERVER["HTTP_HOST"] .$v['image'];
             
        }
        $this->success('返回成功', ['data' => $categorydata]);

    }


    public function deleteType()
    {
        $id = input('post.id');
        $row = \app\admin\model\ykjp\product\Type::where("id", $id)->delete();
        $this->success('返回成功', ['data' =>'删除成功！']);
    }

    //  添加
    public function add(){
        $name = input('post.name');
        $image = input('post.image');
        $props = input('post.props');
        $pid = input('post.pid');

        $model = new \app\admin\model\ykjp\product\Type;
        $time = time();

        $model->insert([
            'image' => $image,
            'createtime' => $time,
            'updatetime' => $time,
            'name' => $name,
            'pid' => $pid
        ]);

        $this->success('返回成功', ['data' =>'添加成功！']);
    }


}
